<template>
  <div>
    <Form ref="form" :model="form" :rules="formRules" style="max-width: 500px; margin: 40px auto 0;">
      <Alert
        :closable="true"
        style="margin-bottom: 24px;"
      >
        确认转账后，资金将直接打入对方账户，无法退回。

      </Alert>
      <FormItem
        label="付款账户"
        class="stepFormText"
      >
        ant-design@alipay.com

      </FormItem>
      <FormItem
        label="收款账户"
        class="stepFormText"
      >
        test@example.com

      </FormItem>
      <FormItem
        label="收款人姓名"
        class="stepFormText"
      >
        Alex

      </FormItem>
      <FormItem
        label="转账金额"
        class="stepFormText"
      >
        ￥ 5,000.00

      </FormItem>
      <Divider/>
      <FormItem
        prop="paymentPassword"
        label="支付密码"
        class="stepFormText"
      >
        <Input
          v-model="form.paymentPassword"
          type="password"
          style="width: 80%;"
        />
      </FormItem>
      <FormItem>
        <Button :loading="loading" type="primary" @click="nextStep">提交</Button>
        <Button style="margin-left: 8px" @click="prevStep">上一步</Button>
      </FormItem>
    </Form>
  </div>
</template>

<script>
export default {
  name: 'Step2',
  data () {
    return {
      form: {
        paymentPassword: '123456'
      },
      formRules: {
        paymentPassword: [
          { required: true, message: '请输入支付密码', trigger: 'blur' }
        ]
      },
      loading: false,
      timer: 0
    }
  },
  methods: {
    nextStep () {
      const that = this
      that.loading = true
      this.$refs['form'].validate((valid) => {
        if (valid) {
          console.log('表单 values', that.form)
          that.timer = setTimeout(function () {
            that.loading = false
            that.$emit('nextStep')
          }, 1500)
        } else {
          that.loading = false
        }
      })
    },
    prevStep () {
      this.$emit('prevStep')
    }
  },
  beforeDestroy () {
    clearTimeout(this.timer)
  }
}
</script>

<style lang="less" scoped>
  .stepFormText {
    margin-bottom: 24px;

    .ant-form-item-label,
    .ant-form-item-control {
      line-height: 22px;
    }
  }

</style>
